var stars = 'sosunn**afns*repsni*';

var rs = stars.split('');
var flag = 0;
for(var i=rs.length -1; i>=0; i--){
    if(rs[i] == '*'){
        flag++;
    }else{
        if(flag == 0)
            continue;
        else{
            rs[i+flag] = rs[i];
            rs[i] = '*';
        }
    }
}
console.log(rs.join(''))
